package com.kantboot.api.email.setting;

import cn.hutool.extra.mail.MailAccount;
import com.kantboot.system.setting.service.ISysSettingService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.HashMap;

@Component
public class ApiEmailSetting {

    @Resource
    private ISysSettingService settingService;

    /**
     * 获取邮箱账号
     */
    public MailAccount getMailAccount() {
        HashMap<String, String> smtp = settingService.getMapByGroupCode("smtp");

        // start: 设置邮箱端口
        String portStr = smtp.get("port");
        int port = 25;
        if (portStr != null) {
            port = Integer.parseInt(portStr);
        }
        // end: 设置邮箱端口

        MailAccount account = new MailAccount();
        account.setHost(smtp.get("host"));
        account.setPort(port);
        account.setAuth(true);
        account.setFrom(smtp.get("email"));
        account.setUser(smtp.get("user"));
        account.setPass(smtp.get("password"));
        return account;
    }


}
